//https://leetcode.cn/problems/powx-n/
//时间复杂度：O(logn)

#include <limits>
#include <math.h>
#include <vector>


class Solution {
  public:

    bool isEqual(double a, double b) {
        return std::abs(a - b) < std::numeric_limits<double>::epsilon();
    }
    bool is_zero(double x, double epsilon = 1e-9) {
        return std::abs(x) < epsilon;
    }

    double recursive_Power(double b, long long  n) {
        
        if (n == 0) {
            return  1.0;
        }
        else if (n&0x01) {
            return myPow(b, n-1)*b;
        }
        else {
            double tmp = recursive_Power(b, n>>1);
            return tmp*tmp;
        }
    }
    double myPow(double b, long long n) {
        if (isEqual(b, 0.0) && n < 0) {
            return 0.0;
        } 
        double res = recursive_Power(b,std::abs(n));
        if(n<0) {
            res = 1.0/res;
        }
        return  res;
    }
};

//https://leetcode.cn/problems/power-of-two/?envType=problem-list-v2&envId=ex0k24j
class Solution {
public:
    bool isPowerOfTwo(int n) {
        if(n<=0) return false;

        for(int i=0;i<n;++i){
            long long pow_num=std::pow(2,i);
            if(pow_num==n) {
                break;
            }else if(pow_num>n){
                return false;
            }
        }
        return true;  
    }
};